﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.Networking;
namespace MrPP.SerriedCabinet
{
    public class BoxModel : NetworkBehaviour {



        [SyncVar(hook = "changeLPage")]
        public int lPage = 0;

        public Action<int> doLPage
        {
            get;
            set;
        }

      
        public void changeLPage(int value)
        {
            lPage = value;
            doLPage?.Invoke(lPage);
        }

        [SyncVar(hook = "changeRPage")]
        public int rPage = 0;

        public Action<int> doRPage
        {
            get;
            set;
        }
        public void changeRPage(int value)
        {

            rPage = value;
            doRPage?.Invoke(rPage);
        }

        [SyncVar(hook = "changeLight")]
        public CabinetGroup.ItemData lit;//亮那个一个

          
        public Action<CabinetGroup.ItemData, CabinetGroup.ItemData> onLight
        {
            get;
            set;
        }

        public void changeLight(CabinetGroup.ItemData val)
        {
           // Debug.LogError(val.text);
            onLight?.Invoke(lit, val);
            lit = val;
        }



        [SyncVar(hook="changeBox")]
        private int box_ = -1;//box
        public int box {
            set {
                box_ = value;
            }
            get {
                return box_;
            }
        }

        public Action<int, int> onBox
        {
            get;
            set;
        }

        public void changeBox(int val) {
            onBox?.Invoke(box_, val);
            box_ = val;
        }

        [SyncVar(hook = "changeMenu")]
        public int menu = -1;//menu

        public Action<int, int> onMenu
        {
            get;
            set;
        }

        public void changeMenu(int val)
        {
            onMenu?.Invoke(menu, val);
            menu = val;
        }

        public class DataSyncList : SyncListStruct<CabinetGroup.ItemData> { }


        public DataSyncList datas = new DataSyncList();
        public Action onRefresh
        {
            get;
            set;
        }
        void changed(DataSyncList.Operation op, int itemIndex)
        {
            onRefresh?.Invoke();
        }
        public void Awake()
        {
            datas.Callback = changed;
        }

        internal void clearLight()
        {
            CabinetGroup.ItemData data = new CabinetGroup.ItemData();
            data.type = Box.Type.None;
            this.lit = data;
        }
    }
}
